/*
 * @Description: 生成Api接口
 * @Author: DHL
 * @Date: 2022-01-30 14:20:12
 * @LastEditors: DHL
 * @LastEditTime: 2023-02-22 14:03:20
 */

import { firstToUpperCase, firstToLowerCase } from '../../utils/codeGenUtils'

export function createUniappApi(codeGenConfig: any) {
  const classNameFirstToUpperCase = firstToUpperCase(codeGenConfig.className)
  const classNameFirstToLowerCase = firstToLowerCase(codeGenConfig.className)

  return `
/*
 * @Description: ${codeGenConfig.genName} - 接口
 * @Author: ${codeGenConfig.genAuthor}
 * @Date: ${codeGenConfig.createData}
 * @LastEditors: ${codeGenConfig.genAuthor}
 * @LastEditTime: ${codeGenConfig.createData}
 */

import { $get, $post, $put } from '@/utils/http'
import { Result } from '@/model/baseModel'
import { ContentTypeEnum, RequestParams } from '@/model/baseHttp'

/**
 * 分页查询
 */
export const api${classNameFirstToUpperCase}Search = (searchParams: RequestParams) =>
  $get<Result<any>>({
    url: '/${classNameFirstToLowerCase}/search',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const api${classNameFirstToUpperCase}GetById = (id: string) =>
  $get<Result<any>>({
    url: '/${classNameFirstToLowerCase}/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const api${classNameFirstToUpperCase}Save = (saveParams: RequestParams) =>
  $post<Result<any>>({
    url: '/${classNameFirstToLowerCase}/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const api${classNameFirstToUpperCase}UpdateById = (updateParams: RequestParams) =>
  $post<Result<any>>({
    url: '/${classNameFirstToLowerCase}/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })


/**
 * 批量逻辑删除
 */
export const api${classNameFirstToUpperCase}LogicBatchDeleteByIds = (ids: string) =>
  $post<Result<any>>({
    url: '/${classNameFirstToLowerCase}/logicBatchDeleteByIds',
    contentType: ContentTypeEnum.form,
    params: { ids: ids }
  })
`
}
